// require("utils.js")
// require("ocr.js")
// Import("utils.js")
Import("A快手.js")
Import("A快手极速版.js")
var PACK_NAME_KSJSB = 'com.kuaishou.nebula' //'com.kuaishou.kgx.novel'

// start快手极速版的浏览任务()
function start快手极速版的浏览任务() {
    if (getExcuteFuncTimes('start快手极速版的浏览任务') >= (isEnableSwitch('ksjsb_moretimes') ? 6 : 4)) {
        if (HANGUP_APPNAMES.find(item => item == '快手极速')) {
            if (getExcuteFuncTimes('start_收集金币_KSJSB') < (isEnableSwitch('ksjsb_moretimes') ? 6 : 4)) {
                start_收集金币_KSJSB()
            } else {

                if (isRunAppTask('taskksjs', '自动切号')) {
                    if (hasExcuteFunc('changeZh_KSJSB')) {
                        if (getExcuteFuncTimes('start_收集金币_KSJSB') < (isEnableSwitch('ksjsb_moretimes') ? 6 : 4)) {
                            start_收集金币_KSJSB()
                        }
                    } else {
                        changeZh_KSJSB()
                        addExcuteFuncTimes('start_收集金币_KSJSB', 0)
                        addExcuteFuncTimes('start快手极速版的浏览任务', 0)
                        setExcuteFunc('changeZh_KSJSB')
                    }
                }
            }
        }

        return
    }

    addExcuteFuncTimes('start快手极速版的浏览任务')

    if (!isRunAppTask('taskksjs', '活跃')) {
        return
    }

    start_浏览任务_KSJSB()

    stopAllApp()

    if (HANGUP_APPNAMES.find(item => item == '快手极速')) {
        start_收集金币_KSJSB()
    }

    startsleep开始休眠并弹窗记录()
}

// start快手的浏览任务()
function start快手的浏览任务() {
    if (isEnableSwitch('ks_pbsyrw')) {
        return
    }

    if (getExcuteFuncTimes('start快手的浏览任务') >= 3 && isEnableSwitch('jsll')) {
        if (getExcuteFuncTimes('start_收集金币_KS') < (isEnableSwitch('ksjsb_moretimes') ? 5 : 3)) {
            start_收集金币_KS()
        }
        return
    }

    if (getExcuteFuncTimes('start快手的浏览任务') >= (isEnableSwitch('ksjsb_moretimes') ? 6 : 3)) {
        if (getExcuteFuncTimes('start_收集金币_KS') < (isEnableSwitch('ksjsb_moretimes') ? 4 : 2)) {
            start_收集金币_KS()
        }
        return
    }
    printinfoOld('ENV' + ENV())
    printinfoOld('start快手的浏览任务')

    startThredTask(() => {
        start_浏览任务_KS()
        var detects = opencv.findMultiColorEx('图色254431.cv');
        if (detects != null) {
            agentOrHidClick(detects[0])
        } else {
            detects = opencv.findImagesEx('图色852359.cv');
            if (detects != null) {
                agentOrHidClick(detects[0])
            } else {
                agentOrHidClickOffectY(ocrTextMoreComplete('快手'), 100)
            }
        }
        agentOrHidClick(ocrText('取消', '暂不开启', '暂不'))
    }, (stepTimes) => {
        var allres = ocrAllRes()
        if (ocrTextMoreByRes(allres, '领取金币', '点赞', '收藏', '更多金币', '活跃', '广告商', '看广告')) {
            agentSwipBigForKS()
            sleep.second(1)
        }
        if (ocrTextMoreByRes(allres, '图文', '直播', '长图', '金币助手', '开车', '入职', '聊天中')) {
            agentSwipBigForKS()
            sleep.second(1)
        }
        if (ocrTextMoreByRes(allres, '开屏广告')) {
            agentSwipBigForKS()
            sleep.second(1)
        }
        if (Math.random() * 100 > 60) {
            if (ocrTextMoreByRes(allres, '购买', '广告', '下单', '保健', '淘宝精选')) {
                sleep.second(getRandomNum(15, 30))
                agentSwipBigForKS()
                sleep.second(1)
            }
        }


        if (ocrTextMoreByRes(allres, '合集')) {
            if (stepTimes % 24 == 0) {
                agentSwipBigForKS()
            }
        } else {
            if (stepTimes % 3 == 0 || stepTimes % 4 == 0) {
                sleep.millisecond(Math.random() * 2000)
                // agentSwipDown(true)
                agentSwipBigForKS()
                sleep.millisecond(Math.random() * 1000 + 500)

                //找图返回目标数组
                var detects = opencv.findImagesEx('图色418085.cv');
                if (detects != null) {
                    // agentSwipDown(true)
                    agentSwipBigForKS()
                }
            }
        }
        // printinfoOld(stepTimes)

        if (stepTimes % 10 == 0) {
            agentOrHidClick(ocrTextMoreByRes(allres, '取消', '禁止', '暂不', '以后', '再说'))
        }
    }, ENV() == 'test' ? 3 * 60 : 16 * 60)

    addExcuteFuncTimes('start快手的浏览任务')

    if (HANGUP_APPNAMES.find(item => item == '快手极速')) {
        start_收集金币_KS()
    }
    startsleep开始休眠并弹窗记录()
}

function changeZh_KS() {
    if (hid.isOn()) {
        return
    }
    start_app_KS()
    skip_主界面的弹窗_KS()

    clickOffectY(0.9, 1, 100, 1)

    ocrWaitForText('获赞')

    skip_主界面的弹窗_KS()

    //切换
    var detects = opencv.findImagesEx('图色683645.cv');
    if (detects != null) {
        agentOrHidClick(detects[0])
    }
    if (ocrWaitForMoreTextMillisecond('切换账号', 6)) {
        click(0.5, 0.94)
        if (ocrText('切换账号')) {
            click(0.5, 0.94)
        }
        if (!ocrText('切换账号')) {
            KS_CURRENT_FLAG = (KS_CURRENT_FLAG == '1' ? '2' : '1')
        }

    }

    stopAllApp()
}

function changeZh_KSJSB() {
    start_app_KSJSB()
    skip_主界面的弹窗_KSJSB()

    clickOffectY(0.9, 1, 100, 1)

    ocrWaitForText('获赞')

    skip_主界面的弹窗_KSJSB()

    //切换
    var detects = opencv.findImagesEx('图色683645.cv');
    if (detects != null) {
        agentOrHidClick(detects[0])
    }
    if (ocrWaitForMoreTextMillisecond('切换账号', 6)) {
        click(0.5, 0.94)
        if (ocrText('切换账号')) {
            click(0.5, 0.94)
        }
        if (!ocrText('切换账号')) {
            KSJSB_CURRENT_FLAG = (KSJSB_CURRENT_FLAG == '1' ? '2' : '1')
        }

        if (ocrText('切换账号')) {
            click(0.5, 0.5)
        }

    }

    stopAllApp()
}